package com.yxjx.duoxue;

import java.util.Properties;

import com.tencent.stat.StatService;
import com.yxjx.duoxue.course.CourseIntroductionActivity;
import com.yxjx.duoxue.global.Globals;
import com.yxjx.duoxue.mta.stat.StatHelper;
import com.yxjx.duoxue.my.FeedbackActivity;
import com.yxjx.duoxue.utils.Utils;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class GuidingScoreDialog extends Dialog implements View.OnClickListener {

	private Context mContext;

	public GuidingScoreDialog(Context context, int theme) {
		super(context, theme);
		mContext = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.segment_score_us);
		
		View mFiveStar = findViewById(R.id.score_five_star);
		View mRemindLater = findViewById(R.id.comment_bad);
		View mReject = findViewById(R.id.score_no);
		
		mFiveStar.setOnClickListener(this);
		mRemindLater.setOnClickListener(this);
		mReject.setOnClickListener(this);
		
		setCancelable(false);
	}

	@Override
	public void onClick(View arg0) {
		Properties prop = StatHelper.getBasicProp(arg0.getContext());
		switch (arg0.getId()) {
		case R.id.score_five_star:
			dismissInternal();
			
			/// MTA stat start
			StatService.trackCustomKVEvent(arg0.getContext(), "event_feedback_score_five_star", prop);
			/// MTA stat end
			
			Utils.writeToSharePreference(getContext(), Yx.KEY_GIVE_FIVE_STAR, "1");
			Utils.writeToSharePreference(getContext(), Yx.KEY_COMMENT_BAD, "");
			Utils.writeToSharePreference(getContext(), Yx.KEY_REJECT, "");
			
			Utils.writeToSharePreference(getContext(), Yx.KEY_HAS_APPOINT_OR_BUY_OR_COMMENT, "0");
			Utils.writeToSharePreference(getContext(), Yx.KEY_LAST_REJECT_VERSION, "");
			Utils.leadUserToRatingInMarket(getContext());
			break;
		case R.id.comment_bad:
			
			dismissInternal();
			/// MTA stat start
			StatService.trackCustomKVEvent(arg0.getContext(), "event_feedback_comment_bad", prop);
			/// MTA stat end
			
			Utils.writeToSharePreference(getContext(), Yx.KEY_COMMENT_BAD, "1");
			Utils.writeToSharePreference(getContext(), Yx.KEY_GIVE_FIVE_STAR, "");
			Utils.writeToSharePreference(getContext(), Yx.KEY_REJECT, "");
			
			Utils.writeToSharePreference(getContext(), Yx.KEY_HAS_APPOINT_OR_BUY_OR_COMMENT, "0");
			Utils.writeToSharePreference(getContext(), Yx.KEY_LAST_REJECT_VERSION, "");
			getContext().startActivity(new Intent(getContext(), FeedbackActivity.class));
			break;
		case R.id.score_no:
			
			dismissInternal();
			/// MTA stat start
			StatService.trackCustomKVEvent(arg0.getContext(), "event_feedback_score_no", prop);
			/// MTA stat end
			
			Utils.writeToSharePreference(getContext(), Yx.KEY_REJECT, "1");
			Utils.writeToSharePreference(getContext(), Yx.KEY_COMMENT_BAD, "" + "");
			Utils.writeToSharePreference(getContext(), Yx.KEY_GIVE_FIVE_STAR, "");
			
			Utils.writeToSharePreference(getContext(), Yx.KEY_LAST_REJECT_VERSION, Utils.getAppVersionName(getContext()));
			Utils.writeToSharePreference(getContext(), Yx.KEY_HAS_APPOINT_OR_BUY_OR_COMMENT, "0");
			break;
		}
	}
	
	private void dismissInternal() {
		Globals.getInstance(mContext).setShowingDialog(false);
		dismiss();
	}

}
